package com.ddone.mode.pubsub;

import com.ddone.util.RabbitMqConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @author ddone
 * @date 2024/4/4-20:10
 */
public class TopicPublisher {

    private final static String EXCHANGE_NAME = "topic_exchange";

    public static void main(String[] args) throws IOException, TimeoutException {

        Connection connection = RabbitMqConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        channel.exchangeDeclare(EXCHANGE_NAME, "topic",true);

        String msg = "商品增加了, id=1001";

        // 发送消息持久化
        channel.basicPublish(EXCHANGE_NAME,"item.xxxy", MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes());

        System.out.println(" [商品服务：] Sent '" + msg + "'");

        channel.close();
        connection.close();


    }
}
